﻿﻿uniform sampler2D texture;

uniform vec4 sourceColor;
uniform vec4 targetColor;

uniform vec4 maskColor;

void main()
{
    // lookup the pixel in the texture
    vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

	if(abs(pixel.r - sourceColor.r) < 0.1 && abs(pixel.g - sourceColor.g) < 0.1 && abs(pixel.b - sourceColor.b) < 0.1)
	{
		gl_FragColor = vec4(targetColor.rgb * maskColor.rgb, targetColor.a * maskColor.a);
	}
	else
	{
		gl_FragColor = vec4(pixel.rgb * maskColor.rgb, pixel.a * maskColor.a);
	}
}